package com.telit.uav.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.xiaolyuh.annotation.Cacheable;
import com.telit.common.dto.DistrictDTO;
import com.telit.firecommand.dto.DistrictInfoDTO;
import com.telit.firecommand.dto.GeoCunDTO;
import com.telit.firecommand.entity.GeoXzqhCun;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


@Repository
public interface GeoXzqhCunDao extends BaseMapper<GeoXzqhCun> {

    int insert(GeoXzqhCun record);

    int insertSelective(GeoXzqhCun record);

    /**
     * 根据code查询name
     *
     * @param code
     *
     * @return
     */
    String queryNameByCode(@Param("code") String code, @Param("codeLength") Integer codeLength);

    /**
     * 根据code查询所有属性
     *
     * @param code
     *
     * @return
     */
    List<GeoXzqhCun> queryAllByCode(@Param("code") String code, @Param("codeLength") Integer codeLength);

    /**
     * 根据code查询省市县乡村
     */
    Map<String, Object> queryAllFieldByCode(@Param("code") String code);

    /**
     * 根据乡code查询村信息
     *
     * @param xiang
     *
     * @return
     */
    List<GeoXzqhCun> listByXiang(@Param("xiang") String xiang);

    /**
     * 根据乡code查询村信息
     *
     * @param xiangs
     *
     * @return
     */
    List<GeoXzqhCun> listByXiangs(@Param("xiangs") List<String> xiangs);

    /**
     * 查询所有的村code
     *
     * @return
     */
    List<DistrictInfoDTO> selectCunCodeList(@Param("districtCode") String districtCode);

    /**
     * 根据code查询村名
     *
     * @param code
     *
     * @return
     */
//	@Cacheable(value = "firecommand:cun:selectNameByCode",depict = "根据code查询村名",key = "#p0")
    String selectNameByCode(@Param("code") String code);

    /**
     * 根据code集合查询村名
     *
     * @param codeList
     *
     * @return
     */
    @Cacheable(value = "firecommand:cun:selectNameByCodeList", depict = "根据code集合查询村名", key = "#p0")
    List<Map<String, String>> selectNameByCodeList(@Param("codeList") List<String> codeList);

    GeoCunDTO getDistrictByPoint(@Param("longitude") String longitude, @Param("latitude") String latitude);

    /**
     * 根据乡查询县
     *
     * @param xiangCode
     *
     * @return
     */
    String queryXianByXiang(@Param("xiangCode") String xiangCode);

    /**
     * 根据村查询乡
     *
     * @param cunCode
     * @param length
     *
     * @return
     */
    String queryXiangByCun(@Param("cunCode") String cunCode, @Param("length") int length);

    /**
     * 通过name查询code
     *
     * @param name
     *
     * @return
     */
    String queryCodeByName(@Param("name") String name);

    /**
     * 根据code查询行政区划全名
     *
     * @param code
     *
     * @return
     */
    String queryAllNameByCode(@Param("code") String code);

    /**
     * 根据村code查询乡name
     *
     * @param xiangCode
     *
     * @return
     */
    //  @Cacheable(value = "firecommand:cun:queryXiangNameByCunCode", depict = "根据村code查询乡name",key = "#p0")
    String queryXiangNameByCunCode(@Param("xiangCode") String xiangCode);

    Map<String, String> getDistrictNameAndCodeByPoint(@Param("longitude") String longitude,
                                                      @Param("latitude") String latitude);

    // @Cacheable(value = "firecommand:cun:queryAllCunByDistrictCode", depict = "根据code查询所有的村",key = "#p0")
    List<String> queryAllCunByDistrictCode(@Param("districtCode") String districtCode);

    List<String> queryAllXiangByDistrictCode(@Param("districtCode") String districtCode);

    List<String> queryAllXianByDistrictCode(@Param("districtCode") String districtCode);

    String queryCunCodeByName(@Param("county") String county, @Param("country") String country,
                              @Param("village") String village);

    List<DistrictInfoDTO> selectCurrentCunCodeList(@Param("districtCode") String districtCode);

    /**
     * 根据code查询name
     *
     * @param code
     *
     * @return
     */
    String queryDistrictNameByCode(@Param("code") String code, @Param("codeLength") Integer codeLength);


    @Select("<script> "
            + "${countSql} "
            + "</script>")
    long countByCode(@Param("countSql") String countSql);

    @Select("<script> "
            + "${querySql} "
            + "</script>")
    List<GeoXzqhCun> selectByCode(@Param("querySql") String querySql);


    List<DistrictDTO> treeDistrict(@Param("areaCode") String areaCode);


    GeoXzqhCun selectByCondition(@Param("provinceCode") String provinceCode,
                                 @Param("cityCode") String cityCode,
                                 @Param("countryCode") String countryCode,
                                 @Param("xiangCode") String xiangCode,
                                 @Param("cunCode") String cunCode);


    List<GeoXzqhCun> selectByParentCode(@Param("provinceCode") String provinceCode,
                                        @Param("cityCode") String cityCode,
                                        @Param("countryCode") String countryCode,
                                        @Param("xiangCode") String xiangCode,
                                        @Param("cunCode") String cunCode,
                                        @Param("groupByName") String groupByName,
                                        @Param("pageSize") Integer pageSize,
                                        @Param("offset") Integer offset);


    String queryOneNameByCode(@Param("code") String code, @Param("codeLength") Integer codeLength);


    List<Map> queryShiXyByCode(@Param("code") String code, @Param("codeLength") Integer codeLength);

    List<Map> queryXyXianByCode(@Param("code") String code, @Param("codeLength") Integer codeLength);

    List<Map> queryXiangXyByCode(@Param("code") String code, @Param("codeLength") Integer codeLength);

}